{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d0f2216e-1211-4adf-967a-cc90883aeef6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "csv_data_path = 'https://raw.githubusercontent.com/turingplanet/pandas-intro/main/public-datasets/small_survey_results.csv'\n",
    "survey_df = pd.read_csv(csv_data_path) # 此数据集包含了StackOverflow上随机的1000份用户调研（列名的具体含义请参考：https://github.com/turingplanet/pandas-intro/blob/main/public-datasets/survey_results_schema.csv）\n",
    "# ：https://github.com/turingplanet/pandas-intro/blob/main/public-datasets/survey_results_schema.csv\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1af1b9d2-da2f-4c57-8a2a-039f25239d53",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>MainBranch</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>Age1stCode</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "      <th>ConvertedComp</th>\n",
       "      <th>Country</th>\n",
       "      <th>CurrencyDesc</th>\n",
       "      <th>...</th>\n",
       "      <th>SurveyEase</th>\n",
       "      <th>SurveyLength</th>\n",
       "      <th>Trans</th>\n",
       "      <th>UndergradMajor</th>\n",
       "      <th>WebframeDesireNextYear</th>\n",
       "      <th>WebframeWorkedWith</th>\n",
       "      <th>WelcomeChange</th>\n",
       "      <th>WorkWeekHrs</th>\n",
       "      <th>YearsCode</th>\n",
       "      <th>YearsCodePro</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20900</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>53040.0</td>\n",
       "      <td>Bulgaria</td>\n",
       "      <td>Bulgarian lev</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>No</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>45.0</td>\n",
       "      <td>23</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>No</td>\n",
       "      <td>45.0</td>\n",
       "      <td>10</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "      <td>867480.0</td>\n",
       "      <td>Norway</td>\n",
       "      <td>Norwegian krone</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>37.0</td>\n",
       "      <td>35</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>14</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "      <td>65000.0</td>\n",
       "      <td>United States</td>\n",
       "      <td>United States dollar</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>ASP.NET Core;React.js</td>\n",
       "      <td>ASP.NET Core;jQuery;Laravel;React.js;Vue.js</td>\n",
       "      <td>A lot less welcome now than last year</td>\n",
       "      <td>45.0</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>19890</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>61.0</td>\n",
       "      <td>21</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Canada</td>\n",
       "      <td>Canadian dollar</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Another engineering discipline (such as civil,...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Somewhat less welcome now than last year</td>\n",
       "      <td>40.0</td>\n",
       "      <td>39</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16393</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>25.0</td>\n",
       "      <td>15</td>\n",
       "      <td>Weekly</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Uruguay</td>\n",
       "      <td>Uruguayan peso</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Another engineering discipline (such as civil,...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Flask</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>40.0</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>51360</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>26.0</td>\n",
       "      <td>13</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>16000.0</td>\n",
       "      <td>12312.0</td>\n",
       "      <td>Egypt</td>\n",
       "      <td>Egyptian pound</td>\n",
       "      <td>...</td>\n",
       "      <td>Neither easy nor difficult</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Another engineering discipline (such as civil,...</td>\n",
       "      <td>Express;React.js</td>\n",
       "      <td>Angular;Angular.js;React.js</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>40.0</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>16771</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United States</td>\n",
       "      <td>United States dollar</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Another engineering discipline (such as civil,...</td>\n",
       "      <td>Angular;Express;Spring</td>\n",
       "      <td>Angular;Express;Spring</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>50.0</td>\n",
       "      <td>41</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>38831</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Netherlands</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>7093</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Indonesia</td>\n",
       "      <td>Indonesian rupiah</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>51843</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>29.0</td>\n",
       "      <td>20</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>90000.0</td>\n",
       "      <td>10680.0</td>\n",
       "      <td>Kenya</td>\n",
       "      <td>Kenyan shilling</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Information systems, information technology, o...</td>\n",
       "      <td>Angular;Angular.js;jQuery;Laravel</td>\n",
       "      <td>Angular;Angular.js;jQuery;Laravel</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 61 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Respondent                      MainBranch Hobbyist   Age Age1stCode  \\\n",
       "0         20900  I am a developer by profession      Yes   NaN         10   \n",
       "1         28235  I am a developer by profession       No  45.0         10   \n",
       "2         26082  I am a developer by profession      Yes  23.0         14   \n",
       "3         19890  I am a developer by profession      Yes  61.0         21   \n",
       "4         16393  I am a developer by profession      Yes  25.0         15   \n",
       "..          ...                             ...      ...   ...        ...   \n",
       "995       51360  I am a developer by profession      Yes  26.0         13   \n",
       "996       16771  I am a developer by profession      Yes   NaN         11   \n",
       "997       38831  I am a developer by profession      Yes   NaN        NaN   \n",
       "998        7093  I am a developer by profession      Yes   NaN        NaN   \n",
       "999       51843  I am a developer by profession      Yes  29.0         20   \n",
       "\n",
       "    CompFreq  CompTotal  ConvertedComp        Country          CurrencyDesc  \\\n",
       "0    Monthly     8000.0        53040.0       Bulgaria         Bulgarian lev   \n",
       "1    Monthly   670000.0       867480.0         Norway       Norwegian krone   \n",
       "2     Yearly    65000.0        65000.0  United States  United States dollar   \n",
       "3        NaN        NaN            NaN         Canada       Canadian dollar   \n",
       "4     Weekly        NaN            NaN        Uruguay        Uruguayan peso   \n",
       "..       ...        ...            ...            ...                   ...   \n",
       "995  Monthly    16000.0        12312.0          Egypt        Egyptian pound   \n",
       "996      NaN        NaN            NaN  United States  United States dollar   \n",
       "997      NaN        NaN            NaN    Netherlands                   NaN   \n",
       "998      NaN        NaN            NaN      Indonesia     Indonesian rupiah   \n",
       "999  Monthly    90000.0        10680.0          Kenya       Kenyan shilling   \n",
       "\n",
       "     ...                  SurveyEase           SurveyLength Trans  \\\n",
       "0    ...                         NaN                    NaN    No   \n",
       "1    ...                        Easy  Appropriate in length    No   \n",
       "2    ...                        Easy  Appropriate in length    No   \n",
       "3    ...                        Easy  Appropriate in length   NaN   \n",
       "4    ...                        Easy  Appropriate in length    No   \n",
       "..   ...                         ...                    ...   ...   \n",
       "995  ...  Neither easy nor difficult  Appropriate in length    No   \n",
       "996  ...                         NaN                    NaN   NaN   \n",
       "997  ...                         NaN                    NaN   NaN   \n",
       "998  ...                         NaN                    NaN   NaN   \n",
       "999  ...                        Easy  Appropriate in length    No   \n",
       "\n",
       "                                        UndergradMajor  \\\n",
       "0    Computer science, computer engineering, or sof...   \n",
       "1    Computer science, computer engineering, or sof...   \n",
       "2    Computer science, computer engineering, or sof...   \n",
       "3    Another engineering discipline (such as civil,...   \n",
       "4    Another engineering discipline (such as civil,...   \n",
       "..                                                 ...   \n",
       "995  Another engineering discipline (such as civil,...   \n",
       "996  Another engineering discipline (such as civil,...   \n",
       "997                                                NaN   \n",
       "998                                                NaN   \n",
       "999  Information systems, information technology, o...   \n",
       "\n",
       "                WebframeDesireNextYear  \\\n",
       "0                                  NaN   \n",
       "1                                  NaN   \n",
       "2                ASP.NET Core;React.js   \n",
       "3                                  NaN   \n",
       "4                                  NaN   \n",
       "..                                 ...   \n",
       "995                   Express;React.js   \n",
       "996             Angular;Express;Spring   \n",
       "997                                NaN   \n",
       "998                                NaN   \n",
       "999  Angular;Angular.js;jQuery;Laravel   \n",
       "\n",
       "                              WebframeWorkedWith  \\\n",
       "0                                            NaN   \n",
       "1                                            NaN   \n",
       "2    ASP.NET Core;jQuery;Laravel;React.js;Vue.js   \n",
       "3                                            NaN   \n",
       "4                                          Flask   \n",
       "..                                           ...   \n",
       "995                  Angular;Angular.js;React.js   \n",
       "996                       Angular;Express;Spring   \n",
       "997                                          NaN   \n",
       "998                                          NaN   \n",
       "999            Angular;Angular.js;jQuery;Laravel   \n",
       "\n",
       "                                WelcomeChange WorkWeekHrs YearsCode  \\\n",
       "0     Just as welcome now as I felt last year        45.0        23   \n",
       "1     Just as welcome now as I felt last year        37.0        35   \n",
       "2       A lot less welcome now than last year        45.0         9   \n",
       "3    Somewhat less welcome now than last year        40.0        39   \n",
       "4     Just as welcome now as I felt last year        40.0        10   \n",
       "..                                        ...         ...       ...   \n",
       "995   Just as welcome now as I felt last year        40.0        10   \n",
       "996   Just as welcome now as I felt last year        50.0        41   \n",
       "997                                       NaN         NaN       NaN   \n",
       "998                                       NaN         NaN       NaN   \n",
       "999   Just as welcome now as I felt last year         8.0         8   \n",
       "\n",
       "    YearsCodePro  \n",
       "0             15  \n",
       "1             22  \n",
       "2              5  \n",
       "3             29  \n",
       "4              3  \n",
       "..           ...  \n",
       "995            3  \n",
       "996           24  \n",
       "997          NaN  \n",
       "998          NaN  \n",
       "999            5  \n",
       "\n",
       "[1000 rows x 61 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b750057-b862-41ea-94d8-fac60ea5789f",
   "metadata": {},
   "source": [
    "## 聚合函数 Aggregating Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ab409076-729e-4add-b3e0-9be593cee2e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48000.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df['ConvertedComp'].median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a8388fac-9b95-4cf7-b0ce-6c4cb92d711c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Respondent       32890.0\n",
       "Age                 29.0\n",
       "CompTotal        56000.0\n",
       "ConvertedComp    48000.0\n",
       "WorkWeekHrs         40.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df.median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "fe20f397-bf1b-4d24-bd61-d1dd22b8ea22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompTotal</th>\n",
       "      <th>ConvertedComp</th>\n",
       "      <th>WorkWeekHrs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1000.00000</td>\n",
       "      <td>697.000000</td>\n",
       "      <td>5.170000e+02</td>\n",
       "      <td>517.000000</td>\n",
       "      <td>628.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>33125.63900</td>\n",
       "      <td>30.810617</td>\n",
       "      <td>3.567064e+06</td>\n",
       "      <td>85067.394584</td>\n",
       "      <td>40.547771</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>18973.33677</td>\n",
       "      <td>9.145613</td>\n",
       "      <td>5.058570e+07</td>\n",
       "      <td>142891.442494</td>\n",
       "      <td>13.103536</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>59.00000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>16665.25000</td>\n",
       "      <td>24.000000</td>\n",
       "      <td>1.500000e+04</td>\n",
       "      <td>19800.000000</td>\n",
       "      <td>40.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>32890.00000</td>\n",
       "      <td>29.000000</td>\n",
       "      <td>5.600000e+04</td>\n",
       "      <td>48000.000000</td>\n",
       "      <td>40.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>50005.25000</td>\n",
       "      <td>36.000000</td>\n",
       "      <td>1.200000e+05</td>\n",
       "      <td>88068.000000</td>\n",
       "      <td>44.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>65633.00000</td>\n",
       "      <td>67.000000</td>\n",
       "      <td>1.120000e+09</td>\n",
       "      <td>1000000.000000</td>\n",
       "      <td>160.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Respondent         Age     CompTotal   ConvertedComp  WorkWeekHrs\n",
       "count   1000.00000  697.000000  5.170000e+02      517.000000   628.000000\n",
       "mean   33125.63900   30.810617  3.567064e+06    85067.394584    40.547771\n",
       "std    18973.33677    9.145613  5.058570e+07   142891.442494    13.103536\n",
       "min       59.00000   13.000000  1.000000e+00        0.000000     3.000000\n",
       "25%    16665.25000   24.000000  1.500000e+04    19800.000000    40.000000\n",
       "50%    32890.00000   29.000000  5.600000e+04    48000.000000    40.000000\n",
       "75%    50005.25000   36.000000  1.200000e+05    88068.000000    44.000000\n",
       "max    65633.00000   67.000000  1.120000e+09  1000000.000000   160.000000"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "00743334-9ff4-49bb-9ce6-8185c918e22b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Windows        0.481829\n",
       "Linux-based    0.282532\n",
       "MacOS          0.233294\n",
       "BSD            0.002345\n",
       "Name: OpSys, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df['OpSys'].value_counts(normalize = True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa03e5bc-81cb-4f4f-93fb-e7cc6bb7ec9a",
   "metadata": {},
   "source": [
    "## 分组 Group By"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8d05d7fd-c159-4e37-bbe2-3e1a6636d498",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "United States     182\n",
       "India             141\n",
       "Germany            55\n",
       "United Kingdom     52\n",
       "Brazil             36\n",
       "                 ... \n",
       "Peru                1\n",
       "Angola              1\n",
       "Côte d'Ivoire       1\n",
       "Somalia             1\n",
       "Malaysia            1\n",
       "Name: Country, Length: 96, dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df['Country'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "93ec29f5-1213-431d-8999-4def97d1b0e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "country_groups = survey_df.groupby(['Country']) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4ec1dfe3-4126-4499-820c-b9f6a0249ed6",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>MainBranch</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>Age1stCode</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "      <th>ConvertedComp</th>\n",
       "      <th>Country</th>\n",
       "      <th>CurrencyDesc</th>\n",
       "      <th>...</th>\n",
       "      <th>SurveyEase</th>\n",
       "      <th>SurveyLength</th>\n",
       "      <th>Trans</th>\n",
       "      <th>UndergradMajor</th>\n",
       "      <th>WebframeDesireNextYear</th>\n",
       "      <th>WebframeWorkedWith</th>\n",
       "      <th>WelcomeChange</th>\n",
       "      <th>WorkWeekHrs</th>\n",
       "      <th>YearsCode</th>\n",
       "      <th>YearsCodePro</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>208</th>\n",
       "      <td>54346</td>\n",
       "      <td>I code primarily as a hobby</td>\n",
       "      <td>Yes</td>\n",
       "      <td>57.0</td>\n",
       "      <td>17</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>China</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Neither easy nor difficult</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Mathematics or statistics</td>\n",
       "      <td>Express;React.js;Ruby on Rails</td>\n",
       "      <td>Express</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>NaN</td>\n",
       "      <td>38</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>36856</td>\n",
       "      <td>I am a student who is learning to code</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>China</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>292</th>\n",
       "      <td>57481</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>21</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>60000.0</td>\n",
       "      <td>China</td>\n",
       "      <td>United States dollar</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>Angular;Angular.js;ASP.NET;ASP.NET Core;Django...</td>\n",
       "      <td>Angular;Angular.js;ASP.NET;ASP.NET Core;Django...</td>\n",
       "      <td>Just as welcome now as I felt last year</td>\n",
       "      <td>40.0</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>500</th>\n",
       "      <td>62271</td>\n",
       "      <td>I am not primarily a developer, but I write co...</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>7000.0</td>\n",
       "      <td>12000.0</td>\n",
       "      <td>China</td>\n",
       "      <td>Chinese Yuan Renminbi</td>\n",
       "      <td>...</td>\n",
       "      <td>Neither easy nor difficult</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Web development or web design</td>\n",
       "      <td>Django;Flask</td>\n",
       "      <td>Django</td>\n",
       "      <td>Somewhat less welcome now than last year</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>705</th>\n",
       "      <td>40997</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>14000.0</td>\n",
       "      <td>24000.0</td>\n",
       "      <td>China</td>\n",
       "      <td>Chinese Yuan Renminbi</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>56.0</td>\n",
       "      <td>4</td>\n",
       "      <td>Less than 1 year</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>786</th>\n",
       "      <td>6888</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>32.0</td>\n",
       "      <td>20</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>China</td>\n",
       "      <td>Chinese Yuan Renminbi</td>\n",
       "      <td>...</td>\n",
       "      <td>Neither easy nor difficult</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Somewhat more welcome now than last year</td>\n",
       "      <td>60.0</td>\n",
       "      <td>11</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>830</th>\n",
       "      <td>28784</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>18</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>10000.0</td>\n",
       "      <td>17148.0</td>\n",
       "      <td>China</td>\n",
       "      <td>Chinese Yuan Renminbi</td>\n",
       "      <td>...</td>\n",
       "      <td>Easy</td>\n",
       "      <td>Appropriate in length</td>\n",
       "      <td>No</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>Django;Flask</td>\n",
       "      <td>Django</td>\n",
       "      <td>Somewhat more welcome now than last year</td>\n",
       "      <td>45.0</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>896</th>\n",
       "      <td>48778</td>\n",
       "      <td>I am a developer by profession</td>\n",
       "      <td>Yes</td>\n",
       "      <td>32.0</td>\n",
       "      <td>14</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>64301.0</td>\n",
       "      <td>China</td>\n",
       "      <td>Chinese Yuan Renminbi</td>\n",
       "      <td>...</td>\n",
       "      <td>Neither easy nor difficult</td>\n",
       "      <td>Too long</td>\n",
       "      <td>No</td>\n",
       "      <td>Computer science, computer engineering, or sof...</td>\n",
       "      <td>ASP.NET;ASP.NET Core</td>\n",
       "      <td>ASP.NET;ASP.NET Core</td>\n",
       "      <td>A lot more welcome now than last year</td>\n",
       "      <td>56.0</td>\n",
       "      <td>14</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 61 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Respondent                                         MainBranch Hobbyist  \\\n",
       "208       54346                        I code primarily as a hobby      Yes   \n",
       "240       36856             I am a student who is learning to code      Yes   \n",
       "292       57481                     I am a developer by profession      Yes   \n",
       "500       62271  I am not primarily a developer, but I write co...      Yes   \n",
       "705       40997                     I am a developer by profession      Yes   \n",
       "786        6888                     I am a developer by profession      Yes   \n",
       "830       28784                     I am a developer by profession      Yes   \n",
       "896       48778                     I am a developer by profession      Yes   \n",
       "\n",
       "      Age Age1stCode CompFreq  CompTotal  ConvertedComp Country  \\\n",
       "208  57.0         17      NaN        NaN            NaN   China   \n",
       "240   NaN        NaN      NaN        NaN            NaN   China   \n",
       "292   NaN         21  Monthly     5000.0        60000.0   China   \n",
       "500   NaN         16  Monthly     7000.0        12000.0   China   \n",
       "705   NaN         18  Monthly    14000.0        24000.0   China   \n",
       "786  32.0         20  Monthly        NaN            NaN   China   \n",
       "830  23.0         18  Monthly    10000.0        17148.0   China   \n",
       "896  32.0         14   Yearly   450000.0        64301.0   China   \n",
       "\n",
       "              CurrencyDesc  ...                  SurveyEase  \\\n",
       "208                    NaN  ...  Neither easy nor difficult   \n",
       "240                    NaN  ...                         NaN   \n",
       "292   United States dollar  ...                        Easy   \n",
       "500  Chinese Yuan Renminbi  ...  Neither easy nor difficult   \n",
       "705  Chinese Yuan Renminbi  ...                         NaN   \n",
       "786  Chinese Yuan Renminbi  ...  Neither easy nor difficult   \n",
       "830  Chinese Yuan Renminbi  ...                        Easy   \n",
       "896  Chinese Yuan Renminbi  ...  Neither easy nor difficult   \n",
       "\n",
       "              SurveyLength Trans  \\\n",
       "208  Appropriate in length    No   \n",
       "240                    NaN   NaN   \n",
       "292  Appropriate in length   NaN   \n",
       "500  Appropriate in length   NaN   \n",
       "705                    NaN   NaN   \n",
       "786  Appropriate in length    No   \n",
       "830  Appropriate in length    No   \n",
       "896               Too long    No   \n",
       "\n",
       "                                        UndergradMajor  \\\n",
       "208                          Mathematics or statistics   \n",
       "240                                                NaN   \n",
       "292  Computer science, computer engineering, or sof...   \n",
       "500                      Web development or web design   \n",
       "705  Computer science, computer engineering, or sof...   \n",
       "786  Computer science, computer engineering, or sof...   \n",
       "830  Computer science, computer engineering, or sof...   \n",
       "896  Computer science, computer engineering, or sof...   \n",
       "\n",
       "                                WebframeDesireNextYear  \\\n",
       "208                     Express;React.js;Ruby on Rails   \n",
       "240                                                NaN   \n",
       "292  Angular;Angular.js;ASP.NET;ASP.NET Core;Django...   \n",
       "500                                       Django;Flask   \n",
       "705                                                NaN   \n",
       "786                                                NaN   \n",
       "830                                       Django;Flask   \n",
       "896                               ASP.NET;ASP.NET Core   \n",
       "\n",
       "                                    WebframeWorkedWith  \\\n",
       "208                                            Express   \n",
       "240                                                NaN   \n",
       "292  Angular;Angular.js;ASP.NET;ASP.NET Core;Django...   \n",
       "500                                             Django   \n",
       "705                                                NaN   \n",
       "786                                                NaN   \n",
       "830                                             Django   \n",
       "896                               ASP.NET;ASP.NET Core   \n",
       "\n",
       "                                WelcomeChange WorkWeekHrs YearsCode  \\\n",
       "208   Just as welcome now as I felt last year         NaN        38   \n",
       "240                                       NaN         NaN       NaN   \n",
       "292   Just as welcome now as I felt last year        40.0         7   \n",
       "500  Somewhat less welcome now than last year        50.0         7   \n",
       "705                                       NaN        56.0         4   \n",
       "786  Somewhat more welcome now than last year        60.0        11   \n",
       "830  Somewhat more welcome now than last year        45.0         6   \n",
       "896     A lot more welcome now than last year        56.0        14   \n",
       "\n",
       "         YearsCodePro  \n",
       "208               NaN  \n",
       "240               NaN  \n",
       "292                 5  \n",
       "500                 3  \n",
       "705  Less than 1 year  \n",
       "786                 8  \n",
       "830                 1  \n",
       "896                 7  \n",
       "\n",
       "[8 rows x 61 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_groups.get_group('China')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "006fa6f4-c517-43ee-886a-42561f58a1dc",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>MainBranch</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>Age1stCode</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "      <th>ConvertedComp</th>\n",
       "      <th>CurrencyDesc</th>\n",
       "      <th>CurrencySymbol</th>\n",
       "      <th>...</th>\n",
       "      <th>SurveyEase</th>\n",
       "      <th>SurveyLength</th>\n",
       "      <th>Trans</th>\n",
       "      <th>UndergradMajor</th>\n",
       "      <th>WebframeDesireNextYear</th>\n",
       "      <th>WebframeWorkedWith</th>\n",
       "      <th>WelcomeChange</th>\n",
       "      <th>WorkWeekHrs</th>\n",
       "      <th>YearsCode</th>\n",
       "      <th>YearsCodePro</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albania</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Algeria</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Argentina</th>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Armenia</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Uruguay</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Uzbekistan</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Venezuela, Bolivarian Republic of...</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Viet Nam</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zambia</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 60 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      Respondent  MainBranch  Hobbyist  Age  \\\n",
       "Country                                                                       \n",
       "Albania                                        2           2         2    2   \n",
       "Algeria                                        2           2         2    1   \n",
       "Angola                                         1           1         1    0   \n",
       "Argentina                                      6           6         6    4   \n",
       "Armenia                                        1           1         1    1   \n",
       "...                                          ...         ...       ...  ...   \n",
       "Uruguay                                        1           1         1    1   \n",
       "Uzbekistan                                     1           1         1    1   \n",
       "Venezuela, Bolivarian Republic of...           1           1         1    1   \n",
       "Viet Nam                                       3           3         3    1   \n",
       "Zambia                                         2           2         2    1   \n",
       "\n",
       "                                      Age1stCode  CompFreq  CompTotal  \\\n",
       "Country                                                                 \n",
       "Albania                                        2         2          2   \n",
       "Algeria                                        2         2          0   \n",
       "Angola                                         0         0          0   \n",
       "Argentina                                      6         5          5   \n",
       "Armenia                                        1         1          1   \n",
       "...                                          ...       ...        ...   \n",
       "Uruguay                                        1         1          0   \n",
       "Uzbekistan                                     1         0          0   \n",
       "Venezuela, Bolivarian Republic of...           1         1          1   \n",
       "Viet Nam                                       2         1          1   \n",
       "Zambia                                         2         1          0   \n",
       "\n",
       "                                      ConvertedComp  CurrencyDesc  \\\n",
       "Country                                                             \n",
       "Albania                                           2             2   \n",
       "Algeria                                           0             2   \n",
       "Angola                                            0             0   \n",
       "Argentina                                         5             6   \n",
       "Armenia                                           1             1   \n",
       "...                                             ...           ...   \n",
       "Uruguay                                           0             1   \n",
       "Uzbekistan                                        0             0   \n",
       "Venezuela, Bolivarian Republic of...              1             1   \n",
       "Viet Nam                                          1             1   \n",
       "Zambia                                            0             2   \n",
       "\n",
       "                                      CurrencySymbol  ...  SurveyEase  \\\n",
       "Country                                               ...               \n",
       "Albania                                            2  ...           2   \n",
       "Algeria                                            2  ...           2   \n",
       "Angola                                             0  ...           0   \n",
       "Argentina                                          6  ...           4   \n",
       "Armenia                                            1  ...           1   \n",
       "...                                              ...  ...         ...   \n",
       "Uruguay                                            1  ...           1   \n",
       "Uzbekistan                                         0  ...           1   \n",
       "Venezuela, Bolivarian Republic of...               1  ...           1   \n",
       "Viet Nam                                           1  ...           2   \n",
       "Zambia                                             2  ...           1   \n",
       "\n",
       "                                      SurveyLength  Trans  UndergradMajor  \\\n",
       "Country                                                                     \n",
       "Albania                                          2      2               2   \n",
       "Algeria                                          2      2               1   \n",
       "Angola                                           0      0               0   \n",
       "Argentina                                        4      4               5   \n",
       "Armenia                                          1      1               1   \n",
       "...                                            ...    ...             ...   \n",
       "Uruguay                                          1      1               1   \n",
       "Uzbekistan                                       0      1               0   \n",
       "Venezuela, Bolivarian Republic of...             1      1               1   \n",
       "Viet Nam                                         2      2               1   \n",
       "Zambia                                           1      1               2   \n",
       "\n",
       "                                      WebframeDesireNextYear  \\\n",
       "Country                                                        \n",
       "Albania                                                    2   \n",
       "Algeria                                                    1   \n",
       "Angola                                                     0   \n",
       "Argentina                                                  4   \n",
       "Armenia                                                    1   \n",
       "...                                                      ...   \n",
       "Uruguay                                                    0   \n",
       "Uzbekistan                                                 1   \n",
       "Venezuela, Bolivarian Republic of...                       1   \n",
       "Viet Nam                                                   2   \n",
       "Zambia                                                     1   \n",
       "\n",
       "                                      WebframeWorkedWith  WelcomeChange  \\\n",
       "Country                                                                   \n",
       "Albania                                                2              2   \n",
       "Algeria                                                2              1   \n",
       "Angola                                                 0              1   \n",
       "Argentina                                              4              4   \n",
       "Armenia                                                1              1   \n",
       "...                                                  ...            ...   \n",
       "Uruguay                                                1              1   \n",
       "Uzbekistan                                             0              1   \n",
       "Venezuela, Bolivarian Republic of...                   1              1   \n",
       "Viet Nam                                               2              2   \n",
       "Zambia                                                 0              1   \n",
       "\n",
       "                                      WorkWeekHrs  YearsCode  YearsCodePro  \n",
       "Country                                                                     \n",
       "Albania                                         2          2             2  \n",
       "Algeria                                         1          2             2  \n",
       "Angola                                          0          0             0  \n",
       "Argentina                                       6          6             6  \n",
       "Armenia                                         1          1             1  \n",
       "...                                           ...        ...           ...  \n",
       "Uruguay                                         1          1             1  \n",
       "Uzbekistan                                      0          1             0  \n",
       "Venezuela, Bolivarian Republic of...            1          1             1  \n",
       "Viet Nam                                        1          2             1  \n",
       "Zambia                                          0          2             2  \n",
       "\n",
       "[96 rows x 60 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df.groupby(['Country']).count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "08d2af93-2e3d-4041-b9fd-a139bce9067a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Windows        3\n",
       "Linux-based    2\n",
       "MacOS          1\n",
       "Name: OpSys, dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_filter = (survey_df['Country'] == 'China')\n",
    "survey_df[country_filter]['OpSys'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "190fbb48-f42a-4e34-a7b9-d4b6126565d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Windows        3\n",
       "Linux-based    2\n",
       "MacOS          1\n",
       "Name: OpSys, dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df.groupby(['Country']).get_group('China')['OpSys'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "06f671a7-77e4-45cb-8203-08ef720d779a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OpSys\n",
       "Windows        3\n",
       "Linux-based    2\n",
       "MacOS          1\n",
       "Name: OpSys, dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_groups['OpSys'].value_counts().loc['China']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "28ec484e-c44c-414f-9c5c-6234d4f70eee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "61105.0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_groups['ConvertedComp'].median().loc['Germany']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "9ef65c97-7c3e-4689-bf93-9ac623153b81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>median</th>\n",
       "      <th>mean</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albania</th>\n",
       "      <td>18546.0</td>\n",
       "      <td>18546.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Algeria</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Argentina</th>\n",
       "      <td>11676.0</td>\n",
       "      <td>19072.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Armenia</th>\n",
       "      <td>66000.0</td>\n",
       "      <td>66000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Uruguay</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Uzbekistan</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Venezuela, Bolivarian Republic of...</th>\n",
       "      <td>12000.0</td>\n",
       "      <td>12000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Viet Nam</th>\n",
       "      <td>9600.0</td>\n",
       "      <td>9600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zambia</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       median     mean\n",
       "Country                                               \n",
       "Albania                               18546.0  18546.0\n",
       "Algeria                                   NaN      NaN\n",
       "Angola                                    NaN      NaN\n",
       "Argentina                             11676.0  19072.8\n",
       "Armenia                               66000.0  66000.0\n",
       "...                                       ...      ...\n",
       "Uruguay                                   NaN      NaN\n",
       "Uzbekistan                                NaN      NaN\n",
       "Venezuela, Bolivarian Republic of...  12000.0  12000.0\n",
       "Viet Nam                               9600.0   9600.0\n",
       "Zambia                                    NaN      NaN\n",
       "\n",
       "[96 rows x 2 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_groups['ConvertedComp'].agg(['median', 'mean'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "662139ed-1d62-4a99-a08e-69647644b724",
   "metadata": {},
   "source": [
    "## 真实场景应用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "5d9c8731-6c5c-4600-aae8-569ec9c9d7f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "87"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_filter = survey_df['Country'] == 'United States' # 选取那些国家名为美国的数据\n",
    "survey_df.loc[country_filter]['LanguageWorkedWith'].str.contains('Python').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "e11f5f96-8754-45cd-a29b-65de23a90b72",
   "metadata": {},
   "outputs": [],
   "source": [
    "country_groups = survey_df.groupby(['Country'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "c4fffdc9-6005-4d00-8960-4bee780d0604",
   "metadata": {},
   "outputs": [],
   "source": [
    "country_uses_python = country_groups['LanguageWorkedWith'].apply(lambda x: x.str.contains('Python').sum()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "4bbdcd32-fb2e-4c5b-b1dd-13519a8841ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "country_respondents = survey_df['Country'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "0e981c7c-285f-4bb4-b238-4243faa48b6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "United States     182\n",
       "India             141\n",
       "Germany            55\n",
       "United Kingdom     52\n",
       "Brazil             36\n",
       "                 ... \n",
       "Peru                1\n",
       "Angola              1\n",
       "Côte d'Ivoire       1\n",
       "Somalia             1\n",
       "Malaysia            1\n",
       "Name: Country, Length: 96, dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_respondents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "cc371039-297c-45b2-9248-7d4120c0c621",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>LanguageWorkedWith</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>182</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>India</th>\n",
       "      <td>141</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>55</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>52</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>36</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Peru</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Côte d'Ivoire</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Somalia</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Malaysia</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Country  LanguageWorkedWith\n",
       "United States       182                  87\n",
       "India               141                  48\n",
       "Germany              55                  22\n",
       "United Kingdom       52                  25\n",
       "Brazil               36                  11\n",
       "...                 ...                 ...\n",
       "Peru                  1                   0\n",
       "Angola                1                   1\n",
       "Côte d'Ivoire         1                   1\n",
       "Somalia               1                   0\n",
       "Malaysia              1                   0\n",
       "\n",
       "[96 rows x 2 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "concated_df = pd.concat([country_respondents, country_uses_python], axis='columns', sort=False) # 将两个统计数集进行结合 (concat会在下一章讲)\n",
    "concated_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "58a9359e-e5fd-4e2d-ab97-861ffaf7d6d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "concated_df.rename(columns = {'Country': 'NumOfUsers', 'LanguageWorkedWith': 'NumOfPythonUsers'}, inplace = True) # 重命名列的名字\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "0a464d66-8f21-4107-b843-1b1baa23061a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NumOfUsers</th>\n",
       "      <th>NumOfPythonUsers</th>\n",
       "      <th>KnowsPython%</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>182</td>\n",
       "      <td>87</td>\n",
       "      <td>47.802198</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>India</th>\n",
       "      <td>141</td>\n",
       "      <td>48</td>\n",
       "      <td>34.042553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>55</td>\n",
       "      <td>22</td>\n",
       "      <td>40.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>52</td>\n",
       "      <td>25</td>\n",
       "      <td>48.076923</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>36</td>\n",
       "      <td>11</td>\n",
       "      <td>30.555556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Peru</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>100.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Côte d'Ivoire</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>100.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Somalia</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Malaysia</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                NumOfUsers  NumOfPythonUsers  KnowsPython%\n",
       "United States          182                87     47.802198\n",
       "India                  141                48     34.042553\n",
       "Germany                 55                22     40.000000\n",
       "United Kingdom          52                25     48.076923\n",
       "Brazil                  36                11     30.555556\n",
       "...                    ...               ...           ...\n",
       "Peru                     1                 0      0.000000\n",
       "Angola                   1                 1    100.000000\n",
       "Côte d'Ivoire            1                 1    100.000000\n",
       "Somalia                  1                 0      0.000000\n",
       "Malaysia                 1                 0      0.000000\n",
       "\n",
       "[96 rows x 3 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "concated_df['KnowsPython%'] = (concated_df['NumOfPythonUsers'] / concated_df['NumOfUsers']) * 100 # 创建一个新列，然后计算出各国使用Python用户的百分比\n",
    "concated_df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bd5f104-2e3d-46a9-a6ac-fcdfa4883661",
   "metadata": {},
   "source": [
    "## 数据清理 Data Cleaning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "6d652057-65c0-4048-854a-6c77452875bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "small_survey_df = survey_df.loc[:5, ['Respondent', 'Hobbyist', 'Age', 'CompFreq', 'CompTotal']]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "1b1e6b69-f34c-445b-8595-3ec9c047c77c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20900</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>8000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>No</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>19890</td>\n",
       "      <td>Yes</td>\n",
       "      <td>61.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16393</td>\n",
       "      <td>Yes</td>\n",
       "      <td>25.0</td>\n",
       "      <td>Weekly</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46721</td>\n",
       "      <td>No</td>\n",
       "      <td>48.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>130000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "0       20900      Yes   NaN  Monthly     8000.0\n",
       "1       28235       No  45.0  Monthly   670000.0\n",
       "2       26082      Yes  23.0   Yearly    65000.0\n",
       "3       19890      Yes  61.0      NaN        NaN\n",
       "4       16393      Yes  25.0   Weekly        NaN\n",
       "5       46721       No  48.0   Yearly   130000.0"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "69cb09fd-bcc4-442b-bc4e-26f7119578f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>No</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46721</td>\n",
       "      <td>No</td>\n",
       "      <td>48.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>130000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "1       28235       No  45.0  Monthly   670000.0\n",
       "2       26082      Yes  23.0   Yearly    65000.0\n",
       "5       46721       No  48.0   Yearly   130000.0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.dropna() # 把含有NaN数值的行都去掉\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "e081b98e-3a61-442c-817a-12e0a2529d48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20900</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>8000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>No</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>19890</td>\n",
       "      <td>Yes</td>\n",
       "      <td>61.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16393</td>\n",
       "      <td>Yes</td>\n",
       "      <td>25.0</td>\n",
       "      <td>Weekly</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46721</td>\n",
       "      <td>No</td>\n",
       "      <td>48.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>130000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "0       20900      Yes   NaN  Monthly     8000.0\n",
       "1       28235       No  45.0  Monthly   670000.0\n",
       "2       26082      Yes  23.0   Yearly    65000.0\n",
       "3       19890      Yes  61.0      NaN        NaN\n",
       "4       16393      Yes  25.0   Weekly        NaN\n",
       "5       46721       No  48.0   Yearly   130000.0"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.dropna(axis = 'columns', how = 'any') # dropna默认就是any\n",
    "small_survey_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "aeb20373-b970-40fd-bb5b-14aa4500e544",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20900</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>8000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>No</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46721</td>\n",
       "      <td>No</td>\n",
       "      <td>48.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>130000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "0       20900      Yes   NaN  Monthly     8000.0\n",
       "1       28235       No  45.0  Monthly   670000.0\n",
       "2       26082      Yes  23.0   Yearly    65000.0\n",
       "5       46721       No  48.0   Yearly   130000.0"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.dropna(axis = 'index', how='any', subset=['CompFreq', 'CompTotal']) # 只查看CompFreq和CompTotal列，将这两列都是NaN的行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "97a2ae33-68c0-42cc-ab0b-6424fca3451d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20900</td>\n",
       "      <td>Yes</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>8000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>NaN</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>19890</td>\n",
       "      <td>Yes</td>\n",
       "      <td>61.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16393</td>\n",
       "      <td>Yes</td>\n",
       "      <td>25.0</td>\n",
       "      <td>Weekly</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46721</td>\n",
       "      <td>NaN</td>\n",
       "      <td>48.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>130000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "0       20900      Yes   NaN  Monthly     8000.0\n",
       "1       28235      NaN  45.0  Monthly   670000.0\n",
       "2       26082      Yes  23.0   Yearly    65000.0\n",
       "3       19890      Yes  61.0      NaN        NaN\n",
       "4       16393      Yes  25.0   Weekly        NaN\n",
       "5       46721      NaN  48.0   Yearly   130000.0"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.replace('No', np.nan, inplace = True) # 将'No'转换成空值\n",
    "small_survey_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "d91a2c02-c210-4c3e-90f9-9ef9bde80caa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "2       26082      Yes  23.0   Yearly    65000.0"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "e357c706-57b5-4f31-be3b-9166230a648a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent  Hobbyist    Age  CompFreq  CompTotal\n",
       "0       False     False   True     False      False\n",
       "1       False      True  False     False      False\n",
       "2       False     False  False     False      False\n",
       "3       False     False  False      True       True\n",
       "4       False     False  False     False       True\n",
       "5       False      True  False     False      False"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.isna() # 查看DataFrame上的数据是否为NaN，结果是False或者True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "31313d44-79a3-4e07-92e6-1c802060d899",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Respondent</th>\n",
       "      <th>Hobbyist</th>\n",
       "      <th>Age</th>\n",
       "      <th>CompFreq</th>\n",
       "      <th>CompTotal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20900</td>\n",
       "      <td>Yes</td>\n",
       "      <td>0.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>8000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28235</td>\n",
       "      <td>0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Monthly</td>\n",
       "      <td>670000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26082</td>\n",
       "      <td>Yes</td>\n",
       "      <td>23.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>65000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>19890</td>\n",
       "      <td>Yes</td>\n",
       "      <td>61.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16393</td>\n",
       "      <td>Yes</td>\n",
       "      <td>25.0</td>\n",
       "      <td>Weekly</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46721</td>\n",
       "      <td>0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>Yearly</td>\n",
       "      <td>130000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Respondent Hobbyist   Age CompFreq  CompTotal\n",
       "0       20900      Yes   0.0  Monthly     8000.0\n",
       "1       28235        0  45.0  Monthly   670000.0\n",
       "2       26082      Yes  23.0   Yearly    65000.0\n",
       "3       19890      Yes  61.0        0        0.0\n",
       "4       16393      Yes  25.0   Weekly        0.0\n",
       "5       46721        0  48.0   Yearly   130000.0"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "small_survey_df.fillna(0) # 将空值全部填为 'Missing'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "6a50ef44-934d-41c6-9edc-98dd6f25b765",
   "metadata": {},
   "outputs": [],
   "source": [
    "survey_df['YearsCode'].replace('Less than 1 year', 0, inplace=True) # 将特定的string转换成数字 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "0a1a7cf9-d51a-4eb1-a63a-446e6d1bcb50",
   "metadata": {},
   "outputs": [],
   "source": [
    "survey_df['YearsCode'] = survey_df['YearsCode'].astype(float) # 改变此列的数据类型\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "61904572-4a90-4319-aa18-da9df7e5f247",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.815937149270482"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "survey_df['YearsCode'].mean() # 查看中位数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f103874e-db0f-4b49-9c47-d53730a1d6d5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "eb7c5898-175d-466b-be9e-f64b8543561b",
   "metadata": {},
   "source": [
    "## 综合练习 Homework"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "30bfbea3-a9fb-4aab-909b-047ea67b12af",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过WebframeWorkedWith和Country列，找到每个国家中最受欢迎的框架。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "40e953b6-bcb9-442f-949a-a6f4ebae0be3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "      <th>12</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ASP.NET Core</td>\n",
       "      <td>jQuery</td>\n",
       "      <td>Laravel</td>\n",
       "      <td>React.js</td>\n",
       "      <td>Vue.js</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Flask</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>Angular</td>\n",
       "      <td>Angular.js</td>\n",
       "      <td>React.js</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>Angular</td>\n",
       "      <td>Express</td>\n",
       "      <td>Spring</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>Angular</td>\n",
       "      <td>Angular.js</td>\n",
       "      <td>jQuery</td>\n",
       "      <td>Laravel</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               0           1         2         3       4     5     6     7   \\\n",
       "0             NaN         NaN       NaN       NaN     NaN   NaN   NaN   NaN   \n",
       "1             NaN         NaN       NaN       NaN     NaN   NaN   NaN   NaN   \n",
       "2    ASP.NET Core      jQuery   Laravel  React.js  Vue.js  None  None  None   \n",
       "3             NaN         NaN       NaN       NaN     NaN   NaN   NaN   NaN   \n",
       "4           Flask        None      None      None    None  None  None  None   \n",
       "..            ...         ...       ...       ...     ...   ...   ...   ...   \n",
       "995       Angular  Angular.js  React.js      None    None  None  None  None   \n",
       "996       Angular     Express    Spring      None    None  None  None  None   \n",
       "997           NaN         NaN       NaN       NaN     NaN   NaN   NaN   NaN   \n",
       "998           NaN         NaN       NaN       NaN     NaN   NaN   NaN   NaN   \n",
       "999       Angular  Angular.js    jQuery   Laravel    None  None  None  None   \n",
       "\n",
       "       8     9     10    11    12  \n",
       "0     NaN   NaN   NaN   NaN   NaN  \n",
       "1     NaN   NaN   NaN   NaN   NaN  \n",
       "2    None  None  None  None  None  \n",
       "3     NaN   NaN   NaN   NaN   NaN  \n",
       "4    None  None  None  None  None  \n",
       "..    ...   ...   ...   ...   ...  \n",
       "995  None  None  None  None  None  \n",
       "996  None  None  None  None  None  \n",
       "997   NaN   NaN   NaN   NaN   NaN  \n",
       "998   NaN   NaN   NaN   NaN   NaN  \n",
       "999  None  None  None  None  None  \n",
       "\n",
       "[1000 rows x 13 columns]"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "framework_df = survey_df['WebframeWorkedWith'].str.split(';', expand = True)\n",
    "framework_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "39156b34-f288-4880-92b8-e48c5693cce0",
   "metadata": {},
   "outputs": [],
   "source": [
    "framework_df.fillna('None', inplace = True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "1d2f4a57-09bc-4f00-a40e-22ae1ce46048",
   "metadata": {},
   "outputs": [],
   "source": [
    "distinct_frameworks = np.unique(framework_df.values)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "ac296f89-4880-488a-9a79-6c47f0562d69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['ASP.NET', 'ASP.NET Core', 'Angular', 'Angular.js', 'Django',\n",
       "       'Drupal', 'Express', 'Flask', 'Gatsby', 'Laravel', 'None',\n",
       "       'React.js', 'Ruby on Rails', 'Spring', 'Symfony', 'Vue.js',\n",
       "       'jQuery'], dtype=object)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distinct_frameworks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "091ce6e1-1623-4214-8c18-607be1136120",
   "metadata": {},
   "outputs": [],
   "source": [
    "country_groups = survey_df.groupby(['Country']) # 给dataframe按照Country进行分组\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "68ee8305-75d4-4717-a000-4260339f3d17",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country\n",
       "Albania                                 0\n",
       "Algeria                                 0\n",
       "Angola                                  0\n",
       "Argentina                               2\n",
       "Armenia                                 1\n",
       "                                       ..\n",
       "Uruguay                                 0\n",
       "Uzbekistan                              0\n",
       "Venezuela, Bolivarian Republic of...    1\n",
       "Viet Nam                                1\n",
       "Zambia                                  0\n",
       "Name: WebframeWorkedWith, Length: 96, dtype: int64"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_groups['WebframeWorkedWith'].apply(lambda x: x.str.contains('jQuery').sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "867b382c-1459-4cab-8dd4-cbe7d808df61",
   "metadata": {},
   "outputs": [],
   "source": [
    "framework_sum_array = []\n",
    "for framework in distinct_frameworks:\n",
    "    new_df = country_groups['WebframeWorkedWith'].apply(lambda x: x.str.contains(framework).sum())\n",
    "    new_df.name = framework\n",
    "    framework_sum_array.append(new_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "f8d67975-93e4-469e-a353-6109db5d8188",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country\n",
       "Albania                                 0\n",
       "Algeria                                 1\n",
       "Angola                                  0\n",
       "Argentina                               0\n",
       "Armenia                                 0\n",
       "                                       ..\n",
       "Uruguay                                 0\n",
       "Uzbekistan                              0\n",
       "Venezuela, Bolivarian Republic of...    0\n",
       "Viet Nam                                1\n",
       "Zambia                                  0\n",
       "Name: ASP.NET Core, Length: 96, dtype: int64"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "framework_sum_array[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "25ccc6aa-3ad1-48fd-94e8-c8c2302e6e23",
   "metadata": {},
   "outputs": [],
   "source": [
    "user_count = survey_df['Country'].value_counts()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "b9b479f1-a993-49d8-abfe-0fa33a73c3fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "United States     182\n",
       "India             141\n",
       "Germany            55\n",
       "United Kingdom     52\n",
       "Brazil             36\n",
       "                 ... \n",
       "Peru                1\n",
       "Angola              1\n",
       "Côte d'Ivoire       1\n",
       "Somalia             1\n",
       "Malaysia            1\n",
       "Name: Country, Length: 96, dtype: int64"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "032795e3-74a1-4d8f-aae6-1ae87a48c015",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>ASP.NET</th>\n",
       "      <th>ASP.NET Core</th>\n",
       "      <th>Angular</th>\n",
       "      <th>Angular.js</th>\n",
       "      <th>Django</th>\n",
       "      <th>Drupal</th>\n",
       "      <th>Express</th>\n",
       "      <th>Flask</th>\n",
       "      <th>Gatsby</th>\n",
       "      <th>Laravel</th>\n",
       "      <th>None</th>\n",
       "      <th>React.js</th>\n",
       "      <th>Ruby on Rails</th>\n",
       "      <th>Spring</th>\n",
       "      <th>Symfony</th>\n",
       "      <th>Vue.js</th>\n",
       "      <th>jQuery</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>182</td>\n",
       "      <td>41</td>\n",
       "      <td>35</td>\n",
       "      <td>48</td>\n",
       "      <td>30</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "      <td>22</td>\n",
       "      <td>20</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>51</td>\n",
       "      <td>10</td>\n",
       "      <td>12</td>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>India</th>\n",
       "      <td>141</td>\n",
       "      <td>22</td>\n",
       "      <td>12</td>\n",
       "      <td>41</td>\n",
       "      <td>28</td>\n",
       "      <td>16</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>19</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>5</td>\n",
       "      <td>16</td>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>55</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>52</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>36</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Peru</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Côte d'Ivoire</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Somalia</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Malaysia</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Country  ASP.NET  ASP.NET Core  Angular  Angular.js  Django  \\\n",
       "United States       182       41            35       48          30      12   \n",
       "India               141       22            12       41          28      16   \n",
       "Germany              55        4             3       13           5       3   \n",
       "United Kingdom       52        6             4        5           3       2   \n",
       "Brazil               36        3             1        7           2       3   \n",
       "...                 ...      ...           ...      ...         ...     ...   \n",
       "Peru                  1        0             0        0           0       0   \n",
       "Angola                1        0             0        0           0       0   \n",
       "Côte d'Ivoire         1        0             0        0           0       1   \n",
       "Somalia               1        1             0        0           0       0   \n",
       "Malaysia              1        0             0        0           0       0   \n",
       "\n",
       "                Drupal  Express  Flask  Gatsby  Laravel  None  React.js  \\\n",
       "United States        3       22     20       9        5     0        51   \n",
       "India                3       17     19       2       12     0        30   \n",
       "Germany              0        6      3       0        2     0         9   \n",
       "United Kingdom       1        4      4       3        1     0        14   \n",
       "Brazil               0        8      4       0        2     0        10   \n",
       "...                ...      ...    ...     ...      ...   ...       ...   \n",
       "Peru                 0        0      0       0        0     0         0   \n",
       "Angola               0        0      0       0        0     0         0   \n",
       "Côte d'Ivoire        0        0      1       0        0     0         0   \n",
       "Somalia              0        0      0       0        0     0         0   \n",
       "Malaysia             0        0      0       0        0     0         0   \n",
       "\n",
       "                Ruby on Rails  Spring  Symfony  Vue.js  jQuery  \n",
       "United States              10      12        2      21      53  \n",
       "India                       5      16        2       9      50  \n",
       "Germany                     2       8        1       7      16  \n",
       "United Kingdom              3       5        0       2      14  \n",
       "Brazil                      3       6        1       6      13  \n",
       "...                       ...     ...      ...     ...     ...  \n",
       "Peru                        0       0        0       0       0  \n",
       "Angola                      0       0        0       0       0  \n",
       "Côte d'Ivoire               0       0        0       0       0  \n",
       "Somalia                     0       0        0       0       1  \n",
       "Malaysia                    0       0        0       0       0  \n",
       "\n",
       "[96 rows x 18 columns]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "concated_df = pd.concat([user_count] + framework_sum_array, axis='columns')\n",
    "concated_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "73ca7efd-4cd7-43e3-bec5-569507203ff1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "United States       jQuery\n",
       "India               jQuery\n",
       "Germany             jQuery\n",
       "United Kingdom    React.js\n",
       "Brazil              jQuery\n",
       "                    ...   \n",
       "Peru               ASP.NET\n",
       "Angola             ASP.NET\n",
       "Côte d'Ivoire       Django\n",
       "Somalia            ASP.NET\n",
       "Malaysia           ASP.NET\n",
       "Length: 96, dtype: object"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "most_popular_df = concated_df.drop(columns = ['Country', 'None']).idxmax(axis = 1) # 找到每行中最多人使用的框架名字\n",
    "most_popular_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "9bb251d6-7869-40cf-9fe4-d3e205f3e0ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "United States       jQuery\n",
       "India               jQuery\n",
       "Germany             jQuery\n",
       "United Kingdom    React.js\n",
       "Brazil              jQuery\n",
       "                    ...   \n",
       "Peru               ASP.NET\n",
       "Angola             ASP.NET\n",
       "Côte d'Ivoire       Django\n",
       "Somalia            ASP.NET\n",
       "Malaysia           ASP.NET\n",
       "Name: most_popular_framwork, Length: 96, dtype: object"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "most_popular_df.name = 'most_popular_framwork'\n",
    "most_popular_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "c46e233a-74d6-4d9b-9dfc-0cf52d95ff47",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>most_popular_framwork</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>182</td>\n",
       "      <td>jQuery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>India</th>\n",
       "      <td>141</td>\n",
       "      <td>jQuery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>55</td>\n",
       "      <td>jQuery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>52</td>\n",
       "      <td>React.js</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>36</td>\n",
       "      <td>jQuery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Peru</th>\n",
       "      <td>1</td>\n",
       "      <td>ASP.NET</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>1</td>\n",
       "      <td>ASP.NET</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Côte d'Ivoire</th>\n",
       "      <td>1</td>\n",
       "      <td>Django</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Somalia</th>\n",
       "      <td>1</td>\n",
       "      <td>ASP.NET</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Malaysia</th>\n",
       "      <td>1</td>\n",
       "      <td>ASP.NET</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>96 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Country most_popular_framwork\n",
       "United States       182                jQuery\n",
       "India               141                jQuery\n",
       "Germany              55                jQuery\n",
       "United Kingdom       52              React.js\n",
       "Brazil               36                jQuery\n",
       "...                 ...                   ...\n",
       "Peru                  1               ASP.NET\n",
       "Angola                1               ASP.NET\n",
       "Côte d'Ivoire         1                Django\n",
       "Somalia               1               ASP.NET\n",
       "Malaysia              1               ASP.NET\n",
       "\n",
       "[96 rows x 2 columns]"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final_df = concated_df.join(most_popular_df)[['Country', 'most_popular_framwork']] # 只查看国家和最受欢迎框架的信息\n",
    "final_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a765a7d6-08b1-498b-b178-8aca099cbed8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
